package com.bluesky.plum.uimodels.render.html.components.containers;

import java.util.List;

import com.bluesky.common.TreeNode;
import com.bluesky.javawebbrowser.domain.html.tags.Tag;
import com.bluesky.javawebbrowser.domain.html.tags.TagType;
import com.bluesky.javawebbrowser.domain.html.tags.form.input.Hidden;
import com.bluesky.javawebbrowser.domain.html.tags.table.TR;
import com.bluesky.javawebbrowser.domain.html.tags.table.Table;
import com.bluesky.plum.uimodels.standard.UIComponent;
import com.bluesky.plum.uimodels.standard.components.containers.form.Form;

public class HForm extends Form {
	private com.bluesky.javawebbrowser.domain.html.tags.form.Form htmlFormTag;
	private Table htmlTableTag;
	private Hidden oumEventName;

	public HForm() {

		htmlFormTag = new com.bluesky.javawebbrowser.domain.html.tags.form.Form();
		htmlFormTag.setAction("processEvent");

		htmlTableTag = new Table();
		htmlTableTag.setBorder(1);
		htmlFormTag.addChild(htmlTableTag);

		// event_name
		oumEventName = new Hidden();
		oumEventName.setName("_oum_event_name");
		oumEventName.setValue("");// Btn1.onClick()

		htmlFormTag.addChild(oumEventName);
	}

	@Override
	public Object getNativeComponent() {

		htmlTableTag.getChildren().clear();

		List<TreeNode> comps = getChildren();
		for (TreeNode tn : comps) {
			UIComponent uic = (UIComponent) tn;

			Tag htmlTag = (Tag) uic.getNativeComponent();

			Tag label = new Tag(TagType.TEXT_BLOCK);
			label.setBody(uic.getCaption());

			TR tr = new TR();
			tr.addColums(new Tag[] { label, htmlTag });

			htmlTableTag.addChild(tr);
		}

		return htmlFormTag;
	}

}
